import java.util.Arrays;

public class Solution {
    public int removeElement(int[] nums,int val) {

        int k = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != val) {
                nums[k] = nums[i];
                k++;
            }
        }

        return k;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int val1=3;
        int[] nums1 = {3, 2, 2, 3};
        int k1 = solution.removeElement(nums1,val1);
        System.out.println(k1);
        System.out.println(Arrays.toString(nums1));

        int[] nums = {0, 1, 2, 2, 3, 0, 4, 2};
        int val2 = 2;
        Solution solution1 = new Solution();
        int k = solution.removeElement(nums, val2);
        System.out.println(k); // 输出 5
        System.out.println(Arrays.toString(nums)); // 输出 [0, 1, 3, 0, 4, _, _, _]

    }
}
